package com.wtb.javatool.service.impl;

import com.wtb.javatool.dao.ProjectMapper;
import com.wtb.javatool.entity.Project;
import com.wtb.javatool.entity.Tag;
import com.wtb.javatool.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class ProjectService implements IProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    /**
     * 查询学生个人项目
     * @param studentId
     */
    @Override
    public ArrayList<Project> SelectProjectByStudentId(int studentId) {
        ArrayList<Project> projects = projectMapper.SelectProjectByStudentId(studentId);
        projects.forEach(project -> {
            project.tagNameArr(project.getTagNames());
        });
        return projects;
    }

    /**
     * 查询公开项目
     * @param isPublic
     */
    @Override
    public ArrayList<Project> SelectProjectByIsPublic(int isPublic) {
        ArrayList<Project> projects = projectMapper.SelectProjectByIsPublic(isPublic);
        projects.forEach(project -> {
            project.tagNameArr(project.getTagNames());
        });
        return projects;
    }

    @Override
    public Project SelectProjectDetailsByProjectId(int projectId) {
        Project project = projectMapper.SelectProjectDetailsByProjectId(projectId);
        project.studentsNameArr(project.getStudentsNames());
        project.tagNameArr(project.getTagNames());
        return project;

    }

    @Override
    public ArrayList<Project> SelectProjectByInfo(String projectName, String studentName, int stars) {
        ArrayList<Project> projects = projectMapper.SelectProjectByInfo(projectName, studentName, stars);
        projects.forEach(project -> {
            project.tagNameArr(project.getTagNames());
        });
        return projects;
    }

    @Override
    public ArrayList<Project> SelectStudentProjectByInfo(int studentId, String projectName, String studentName, int stars) {
        ArrayList<Project> projects = projectMapper.SelectStudentProjectByInfo(studentId, projectName, studentName, stars);
        projects.forEach(project -> {
            project.tagNameArr(project.getTagNames());
        });
        return projects;
    }


    /**
     * 查询项目根据分类
     * @param typeId,optionId,fatherOptionId
     */
    @Override
    public ArrayList<Project> SelectProjectByCategory(int typeId, int optionId, int fatherOptionId) {
        ArrayList<Project> projects = projectMapper.SelectProjectByCategory(typeId, optionId, fatherOptionId);
        return projects;
    }

    /**
     * 添加项目
     *
     * @param project
     */
    @Override
    public Integer addProject(Project project) {

        return  projectMapper.addProject(project);
    }

    /**
     * 更新项目
     *
     * @param project
     */
    @Override
    public Integer updateProject(Project project) {
        return   projectMapper.updateProject(project);
    }

    @Override
    public ArrayList<Tag> SelectAllTag() {
        ArrayList<Tag> Tags=projectMapper.SelectAllTag();
        return Tags;
    }
}
